package com.zsgeek.wisdchain.qutu.base.SQL;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.zsgeek.wisdchain.qutu.tools.LogUtil;


/**
 * 管理库 、表创建
 * Created by whb on 2018/7/17.
 */

public class QuTuDBHelper extends SQLiteOpenHelper {
    //    private static final int DB_VERSION = 1;
    public static final String TABLE_NAME_MarketSearchTable = "QuTuTable";  //默认表
    private static final String DB_NAME_GuoBiAllTread = "QuTu.db";
    private String tableName;

    public QuTuDBHelper(Context context, String tableName) {
        super(context, DB_NAME_GuoBiAllTread, null, 1);
        if (tableName == null)
            this.tableName = TABLE_NAME_MarketSearchTable;
        else
            this.tableName = tableName;
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        // create table Orders(Id integer primary key, CustomName text, OrderPrice integer, Country text);
        sqLiteDatabase.execSQL(createTable(tableName));
//        sqLiteDatabase.execSQL(createTable(TABLE_NAME_MarketSearchTableBTC));
//        sqLiteDatabase.execSQL(createTable(TABLE_NAME_MarketSearchTableETH));
//        String sql = "create table if not exists " + TABLE_NAME_MarketSearchTable
//                + " (Id integer primary key autoincrement, FCoinType integer, FShortName text, Furl text" +
//                ", Fcount1 integer, Fcount2 integer, FlockCurrent integer, FNewDealPrice text" +
//                ", FTodayRiseFall text, H24Volume text, FMarket text, FName text, FTradeType integer)";
//        sqLiteDatabase.execSQL(sql);
    }

    public String createTable(String tableName) {
        LogUtil.e("创建表：" + tableName);
        return "create table if not exists " + tableName
                + " (Id integer primary key autoincrement, KeyName text, CoinAddress text, Keystore text)";
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
//        String sql = "DROP TABLE IF EXISTS " + TABLE_NAME_MarketSearchTable;
        sqLiteDatabase.execSQL(dropTable(tableName));
//        sqLiteDatabase.execSQL(dropTable(TABLE_NAME_MarketSearchTableBTC));
//        sqLiteDatabase.execSQL(dropTable(TABLE_NAME_MarketSearchTableETH));
        onCreate(sqLiteDatabase);
    }

    private String dropTable(String tableName) {
        return "DROP TABLE IF EXISTS " + tableName;
    }
}
